package org.javaqq.face.main.lookandfeel;

import java.awt.Font;
import java.awt.Insets;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.font.TextAttribute;
import java.util.HashMap;

import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JButton;

import org.javaqq.face.resources.Info;
import org.javaqq.face.resources.ResourcesManager;

public class JavaQQLinkButton extends JButton {
	 /**
     * Create a new RolloverButton.
     */
    public JavaQQLinkButton() {
        decorate();
    }

    public JavaQQLinkButton(String text) {
    	HashMap<TextAttribute, Object> hm = new HashMap<TextAttribute, Object>();
    	
        String fontName
            = ResourcesManager.getResourcesManagerFactory().getDefaultsValue(Info.JAVAQQ_FONT_NAME);
        String titleFontSize
            = ResourcesManager.getResourcesManagerFactory().getDefaultsValue(Info.JAVAQQ_FONT_SIZE);
        hm.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
        hm.put(TextAttribute.SIZE, titleFontSize);
    //    hm.put(TextAttribute.FAMILY, fontName);
        hm.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
        

        Font font = new Font(hm);
        
        //this.setFont(font);
        this.setText(text);

        decorate();
    }

    public JavaQQLinkButton(Action action) {
        super(action);
        decorate();
    }

    /**
     * Create a new RolloverButton.
     *
     * @param icon the icon to use on the button.
     */
    public JavaQQLinkButton(Icon icon) {
        super(icon);
        decorate();
    }

    /**
     * Create a new RolloverButton.
     *
     * @param text the button text.
     * @param icon the button icon.
     */
    public JavaQQLinkButton(String text, Icon icon) {
        super(text, icon);
        decorate();
    }


    /**
     * Decorates the button with the approriate UI configurations.
     */
    private void decorate() {
        setBorderPainted(false);
        setOpaque(true);

        setContentAreaFilled(false);
        setMargin(new Insets(1, 1, 1, 1));

        addMouseListener(new MouseAdapter() {
            public void mouseEntered(MouseEvent e) {
                if (isEnabled()) {
                    setBorderPainted(true);

                    // Handle background border on mac.
               //     if (!Spark.isMac()) {
               //         setContentAreaFilled(true);
               //     }
                }
            }

            public void mouseExited(MouseEvent e) {
                setBorderPainted(false);
                setContentAreaFilled(false);
            }
        });

    }

}
